import request from '@/utils/request';
import { sm2 } from 'sm-crypto';
// 签名认证V2 - 第三方获取访问令牌
export const getSignV2GetAccessToken = (params) =>
  request.get('/auth/signV2/getAccessToken', { params: { ...params } });

// 签名认证V2 - 用户登录
export const postSignV2Login = (body) => request.post('/auth/signV2/login', body);

// 签名认证V2 - 用户注销
export const getSignV2Logout = () => request.get('/auth/signV2/logout');

// 签名认证V2 - 签字校验
export const postSignV2SignComfirm = (body) => request.post('/auth/signV2/signComfirm', body);

// 获取菜单
export const getClientMenuTreeByRoleAndApplication = (params) => {
  return request.get('/brac/menu/getClientMenuTreeByRoleAndApplication', {
    params: {
      ...params
    }
  });
};

// 模拟登录
export const login = () => {
  const encryptSingle = (value) => {
    const publicKey = '025f735e103ee29ac7948d1c2d3cb32cea6a2b4cd1401adab89087d7076e0f57fe';
    const slot = 'NcSgcc@2017.';
    if (value) {
      const res = sm2.doEncrypt(slot + value, publicKey, 1);
      return `04${res}`;
    } else {
      return '';
    }
  };
  const params = {
    loginType: 'pc',
    userName: `${window.NC_PROJECT_CONFIG.projectName}Master`,
    password: encryptSingle('1234Qwer@')
  };
  return request.post('/auth/signV2/login', params);
};
